package com.yang.net.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

/**
 * @author yds
 * @program net-sokect_stduy
 * @description 使用udp协议做socket通讯一端
 * 不需要建立来连接
 * @create 2020-09-30 16:12
 **/
public class UdpCilent {
    public static void main(String[] args) throws IOException {
        //不需要建立连接，知道发现地址就行
        InetAddress localhost = InetAddress.getByName("localhost");

        DatagramSocket socket = new DatagramSocket();
        String msg="发送消息";
        //建议一个数据包
        DatagramPacket packet=new DatagramPacket(msg.getBytes(),0,msg.getBytes().length,localhost,9000);

        socket.send(packet);

        socket.close();
    }
}